package cn.yuan.xiaoyu.wangmodule.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import cn.yuan.xiaoyu.R;
import cn.yuan.xiaoyu.commonmodule.activity.BaseActivity;
import cn.yuan.xiaoyu.commonmodule.adapter.PagerAdapter;
import cn.yuan.xiaoyu.commonmodule.utils.StatusBarCompatUtils;
import cn.yuan.xiaoyu.wangmodule.fragment.WangWangContactFragment;
import cn.yuan.xiaoyu.wangmodule.fragment.WangWangFindFragment;
import cn.yuan.xiaoyu.wangmodule.fragment.WangWangMeFragment;
import cn.yuan.xiaoyu.wangmodule.fragment.WangwangListFragment;
import cn.yuan.xiaoyu.wangmodule.view.WangWangAddPoPuwindow;

/**
 * Created by yukuoyuan on 2017/3/1.
 * 这是一个仿微信的旺旺的界面
 */

public class WangWangActivity extends BaseActivity implements WangWangAddPoPuwindow.OnBtnClickListener {
    @Bind(R.id.vp_main)
    ViewPager vpMain;
    @Bind(R.id.bt_main_tab_ww)
    Button btMainTabWw;
    @Bind(R.id.bt_main_tab_contact)
    Button btMainTabContact;
    @Bind(R.id.bt_main_tab_find)
    Button btMainTabFind;
    @Bind(R.id.bt_main_tab_me)
    Button btMainTabMe;
    private List<Fragment> fragments = new ArrayList<>();
    private WangWangAddPoPuwindow wangWangAddPoPuwindow;

    @Override
    protected void bindPresenter() {

    }

    @Override
    protected void initData(Bundle extras) {
        fragments.add(new WangwangListFragment());
        fragments.add(new WangWangContactFragment());
        fragments.add(new WangWangFindFragment());
        fragments.add(new WangWangMeFragment());
        PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), fragments);
        vpMain.setAdapter(pagerAdapter);
        vpMain.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {

                clearstatus();
                switch (position) {
                    case 0:
                        btMainTabWw.setSelected(true);
                        break;
                    case 1:
                        btMainTabContact.setSelected(true);
                        break;
                    case 2:
                        btMainTabFind.setSelected(true);
                        break;
                    case 3:
                        btMainTabMe.setSelected(true);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        vpMain.setOffscreenPageLimit(3);
        if (wangWangAddPoPuwindow != null) {
            wangWangAddPoPuwindow.setOnBtnClickListener(this);
        }
    }

    private void clearstatus() {
        btMainTabWw.setSelected(false);
        btMainTabContact.setSelected(false);
        btMainTabFind.setSelected(false);
        btMainTabMe.setSelected(false);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_wangwang;
    }

    @Override
    protected void initToolbar() {
        StatusBarCompatUtils.compat(this, Color.BLACK);
        clearstatus();
        btMainTabWw.setSelected(true);

    }

    @OnClick({R.id.iv_add, R.id.iv_search, R.id.bt_main_tab_ww, R.id.bt_main_tab_contact, R.id.bt_main_tab_find, R.id.bt_main_tab_me})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_add:
                if (wangWangAddPoPuwindow == null || !wangWangAddPoPuwindow.isShowing()) {
                    wangWangAddPoPuwindow = new WangWangAddPoPuwindow(WangWangActivity.this);
                }
                wangWangAddPoPuwindow.showAsDropDown(view);
                break;
            case R.id.iv_search:
                break;
            case R.id.bt_main_tab_ww:
                clearstatus();
                btMainTabWw.setSelected(true);
                vpMain.setCurrentItem(0, false);
                break;
            case R.id.bt_main_tab_contact:
                clearstatus();
                btMainTabContact.setSelected(true);
                vpMain.setCurrentItem(1, false);
                break;
            case R.id.bt_main_tab_find:
                clearstatus();
                btMainTabFind.setSelected(true);
                vpMain.setCurrentItem(2, false);
                break;
            case R.id.bt_main_tab_me:
                clearstatus();
                btMainTabMe.setSelected(true);
                vpMain.setCurrentItem(3, false);
                break;
        }
    }

    @Override
    public void onBtnGroupClickListener() {

    }

    @Override
    public void onBtnFriendsClickListener() {

    }

    @Override
    public void onBtnScanClickListener() {

    }

    @Override
    public void onBtnFadebackClickListener() {

    }
}
